# @Time    : 2020/4/8 12:24
# @Author  : wumao
# @Email   : kanhebei@dingtalk.com

from . import home_bp
from .helper.func import view
from .helper.decorator import first_page_301
from ...models import Tag, Article


@home_bp.route('/tag/<int:tag_id>')
@home_bp.route('/tag/<int:tag_id>/page/<int:page>')
@first_page_301
def tag_select(tag_id, page=1):
    _tag = Tag.query.get_or_404(tag_id)
    query = Article.query.with_parent(_tag).order_by(Article.id.desc())
    record = query.paginate(page=page, per_page=20)
    return view(
        'tag.html',
        record=record.items,
        pagination=record,
        tag=_tag
    )
